/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-03-25
 * Time: 14:40
 */
public class test1 {

    static int a = 0;

    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(() ->{
            while (true){
                synchronized (locker){
                    if(a>200){
                        break;
                    }
                    if(a%2==0){
                        System.out.println(Thread.currentThread().getName()+"-"+a);
                        a++;
                        locker.notify();
                    }else{
                        try {
                            locker.wait();
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        t1.setName("t1");


        Thread t2 = new Thread(() ->{
           while(true){
               synchronized (locker){
                   if(a>200){
                       break;
                   }
                   if(a%2==1){
                       System.out.println(Thread.currentThread().getName()+"-"+a);
                       a++;
                       locker.notify();
                   }else {
                       try {
                           locker.wait();
                       }catch (Exception e){
                            e.printStackTrace();
                       }
                   }
               }
           }
        });
        t2.setName("t2");
        t1.start();
        t2.start();
    }

}
